package com.mooco.dongba.common.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(2)
public class SysCacheAspect {
    //@Pointcut("@annotation(com.mooco.dongba.common.anotation.RequiredCache)")
    @Pointcut("bean(sysUserServiceImpl)")
    public void doCache() {}

    @Around("doCache()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            System.out.println("Get data from cache");
            /* 测试切面链的执行顺序 */
            System.out.println("cache 01");
            System.out.println("cache 02");
            System.out.println("cache 03");
            System.out.println("cache 04");
            System.out.println("cache 05");
            System.out.println("cache 06");
            Object object = joinPoint.proceed();
            System.out.println("Put data to cache");
            return object;
        } catch (Throwable e) {
            throw e;
        }
    }

    @Before("doCache()")
    public void doBefore() {
        System.out.println("缓存切面");
    }
}
